package com.psm.listeners;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;

public class SplitMergeOptionsListener implements ActionListener
{
    private JTextField txtSelectPDF;
    private JButton btnMergePDF;
    private JButton btnDirBrowse;
    private JTextField txtSrcDirectory;
    private JLabel lblSrcDirectory;
    private JButton btnSplitPDF;
    private JTextField txtToPage;
    private JLabel lblToPage;
    private JTextField txtFromPage;
    private JLabel lblFromPage;
    private JComboBox comboSplitOptions;
    private JLabel lblSplitOptions;
    private JButton btnSrcBrowse;
    private JLabel lblSelectPDF;
    private JRadioButton radioMerge;
    private JRadioButton radioSplit;
    private TitledBorder splitTitle;
    private TitledBorder mergeTitle;
    private JFrame frame;

    public SplitMergeOptionsListener(JTextField txtSelectPDF, JButton btnMergePDF, JButton btnDirBrowse, JTextField txtSrcDirectory, JLabel lblSrcDirectory, JButton btnSplitPDF, JTextField txtToPage, JLabel lblToPage,
	    JTextField txtFromPage, JLabel lblFromPage, JComboBox comboSplitOptions, JLabel lblSplitOptions, JButton btnSrcBrowse, JLabel lblSelectPDF, JRadioButton radioMerge, JRadioButton radioSplit,
	    TitledBorder splitTitle, TitledBorder mergeTitle, JFrame frame)
    {
	this.txtSelectPDF = txtSelectPDF;
	this.btnMergePDF = btnMergePDF;
	this.btnDirBrowse = btnDirBrowse;
	this.txtSrcDirectory = txtSrcDirectory;
	this.lblSrcDirectory = lblSrcDirectory;
	this.btnSplitPDF = btnSplitPDF;
	this.txtToPage = txtToPage;
	this.lblToPage = lblToPage;
	this.txtFromPage = txtFromPage;
	this.lblFromPage = lblFromPage;
	this.comboSplitOptions = comboSplitOptions;
	this.lblSplitOptions = lblSplitOptions;
	this.btnSrcBrowse = btnSrcBrowse;
	this.lblSelectPDF = lblSelectPDF;
	this.radioMerge = radioMerge;
	this.radioSplit = radioSplit;
	this.splitTitle = splitTitle;
	this.mergeTitle = mergeTitle;
	this.frame = frame;
    }

    @Override
    public void actionPerformed(ActionEvent ae)
    {
	if ( ae.getSource() == radioSplit )
	{
	    txtSelectPDF.setEnabled( true );
	    btnSplitPDF.setEnabled( true );
	    txtToPage.setEnabled( false );
	    lblToPage.setEnabled( false );
	    txtFromPage.setEnabled( false );
	    lblFromPage.setEnabled( false );
	    comboSplitOptions.setEnabled( true );
	    lblSplitOptions.setEnabled( true );
	    btnSrcBrowse.setEnabled( true );
	    lblSelectPDF.setEnabled( true );
	    splitTitle.setTitleColor( Color.black );
	    
	    btnMergePDF.setEnabled( false );
	    btnDirBrowse.setEnabled( false );
	    txtSrcDirectory.setEnabled( false );
	    lblSrcDirectory.setEnabled( false );
	    mergeTitle.setTitleColor( Color.gray );
	    SwingUtilities.updateComponentTreeUI( frame );
	}
	else if ( ae.getSource() == radioMerge )
	{
	    btnMergePDF.setEnabled( true );
	    btnDirBrowse.setEnabled( true );
	    txtSrcDirectory.setEnabled( true );
	    lblSrcDirectory.setEnabled( true );
	    mergeTitle.setTitleColor( Color.black );
	    
	    txtSelectPDF.setEnabled( false );
	    btnSplitPDF.setEnabled( false );
	    txtToPage.setEnabled( false );
	    lblToPage.setEnabled( false );
	    txtFromPage.setEnabled( false );
	    lblFromPage.setEnabled( false );
	    comboSplitOptions.setEnabled( false );
	    lblSplitOptions.setEnabled( false );
	    btnSrcBrowse.setEnabled( false );
	    lblSelectPDF.setEnabled( false );
	    splitTitle.setTitleColor( Color.gray );
	    SwingUtilities.updateComponentTreeUI( frame );
	}
    }
}
